<template>
    <div>
        <input type="text" v-model="name" placeholder="请输入姓名"/> 
        <button @click="addPerson">添加</button>
        <ul>
            <li v-for="p in $store.state.persons" :key="p.id">{{ p.name }}</li>
        </ul>
    </div>
    
</template>

<script>
export default {
    name: 'PersonComponent',
    data() {
        return { 
            title: 'Hello, world!',
            message: 'Welcome to my Vue app!',
            name: ''
        }
    },
    methods: {
        addPerson() {
            const nPerson = {name: this.name, id: Date.now()}
            this.$store.commit('ADD_PERSON', nPerson)
            this.name = ''
        }
    }
}
</script>

<style scoped>
    li {
        color: rgb(69, 213, 170);
    }
</style>
